"use strict";
cc._RF.push(module, '94a80HxVEpFgoM9EjM/1I3/', 'GameArenaView');
// scripts/GameArenaView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
},
    r = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
},
    s = void 0 && (void 0).__generator || function (t, e) {
  var o,
      i,
      n,
      a,
      r = {
    label: 0,
    sent: function sent() {
      if (1 & n[0]) throw n[1];
      return n[1];
    },
    trys: [],
    ops: []
  };
  return a = {
    next: s(0),
    "throw": s(1),
    "return": s(2)
  }, "function" == typeof Symbol && (a[Symbol.iterator] = function () {
    return this;
  }), a;

  function s(t) {
    return function (e) {
      return l([t, e]);
    };
  }

  function l(a) {
    if (o) throw new TypeError("Generator is already executing.");

    for (; r;) {
      try {
        if (o = 1, i && (n = 2 & a[0] ? i["return"] : a[0] ? i["throw"] || ((n = i["return"]) && n.call(i), 0) : i.next) && !(n = n.call(i, a[1])).done) return n;

        switch (i = 0, n && (a = [2 & a[0], n.value]), a[0]) {
          case 0:
          case 1:
            n = a;
            break;

          case 4:
            return r.label++, {
              value: a[1],
              done: !1
            };

          case 5:
            r.label++, i = a[1], a = [0];
            continue;

          case 7:
            a = r.ops.pop(), r.trys.pop();
            continue;

          default:
            if (!(n = (n = r.trys).length > 0 && n[n.length - 1]) && (6 === a[0] || 2 === a[0])) {
              r = 0;
              continue;
            }

            if (3 === a[0] && (!n || a[1] > n[0] && a[1] < n[3])) {
              r.label = a[1];
              break;
            }

            if (6 === a[0] && r.label < n[1]) {
              r.label = n[1], n = a;
              break;
            }

            if (n && r.label < n[2]) {
              r.label = n[2], r.ops.push(a);
              break;
            }

            n[2] && r.ops.pop(), r.trys.pop();
            continue;
        }

        a = e.call(t, r);
      } catch (s) {
        a = [6, s], i = 0;
      } finally {
        o = n = 0;
      }
    }

    if (5 & a[0]) throw a[1];
    return {
      value: a[0] ? a[1] : void 0,
      done: !0
    };
  }
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var l = t("GlobalUserData"),
    c = t("GameLogic"),
    d = t("BoxGetView"),
    h = t("Util"),
    p = t("Bounce"),
    u = t("Global"),
    f = t("BaseStorage"),
    m = t("TimeUtil"),
    _ = t("ArenaRoleInfo"),
    y = t("HallConstant"),
    g = t("Hint"),
    v = t("SceneManager"),
    C = cc._decorator,
    b = C.ccclass,
    w = C.property,
    S = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.openBox = null, e.portraitNode = null, e.titleNode = null, e.tagNode = null, e.powerValue = null, e.boxNode = null, e.redPointNode = null, e.boxValue = null, e.portraitIcon = null, e.nameLabel = null, e.timeLabel = null, e.rolePrefab = null, e.pfb_box = null, e.frame_buttom = null, e.blocks = [], e.headUrlList = [], e.rNameList = [], e.rHeadSpriteList = [], e._roles = [], e.posList = [cc.v3(-300, 82), cc.v3(-300, -188), cc.v3(300, -188), cc.v3(300, 82), cc.v3(0, -68.525)], e.starNumList = [1, 1, 2, 3, 3], e._gameControl = null, e._gameLogic = null, e._nameArr = [], e._headUrlArr = [], e.videoIcon = null, e.TTVideoIcon = null, e.btnVideo = null, e.btnRefreshOnce = null, e.loopDisplay = function () {
      var t = this.rHeadSpriteList[h.Util.getRandomInt(0, this.rHeadSpriteList.length - 1)];
      t && (this.portraitIcon.spriteFrame = t);
    }, e.loopRoleData = function () {
      if (this._index >= 5) return this.portraitNode.active = !1, this.frame_buttom.interactable = !0, this.btnRefreshOnce.interactable = !0, this.node.getChildByName("btn_back").getComponent(cc.Button).interactable = !0, this.unschedule(this.loopRoleData), this.unschedule(this.loopDisplay), void this.addRoleEvent();
      this.headUrl = this.selectInfo(this._headUrlArr, this.headUrlList), this.nameLabel.string = this.selectInfo(this._nameArr, this.rNameList);
      var t = this.posList[this._index],
          e = this.starNumList[this._index],
          o = {
        name: this.nameLabel.string,
        headUrl: this.headUrl,
        power: 0,
        star: e,
        grade: 1,
        pos: {
          x: t.x,
          y: t.y
        }
      },
          i = cc.instantiate(this.rolePrefab);
      this._roles.push(i), this._index++, i.getComponent(_["default"]).initViewData(this._gameControl, this, this._gameLogic, o, this.node, !0);
    }, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    this.TTVideoIcon.active = !1, h.Util.is_tt() && (this.videoIcon.active = !1, this.TTVideoIcon.active = !0), this.btnRefreshOnce.node.active = !1, h.Util.is_tt() ? this.btnRefreshOnce.node.active = !0 : this.btnVideo.y = -255, this.frame_buttom.interactable = !1, this.btnRefreshOnce.interactable = !1, this._gameLogic = new c.GameLogic();
  }, e.prototype.onEnable = function () {
    var t = this;
    h.Util.event_dispatcher.register(this), l["default"].isMatchView = !0, this.titleNode.y = 530, this.tagNode.y = -30;
    var e = cc.v3(0, 280),
        o = cc.v3(0, -80);
    cc.tween(this.titleNode).to(.5, {
      position: e
    }).call(function () {
      cc.tween(t.tagNode).to(.5, {
        position: o
      }, {
        easing: "elasticOut"
      }).start();
    }).start(), this.iscb = !0, h.Util.show_matrixAd();
  }, e.prototype.closeMatrixAdCB = function () {
    this.iscb && h.Util.showSingleCustomAd();
  }, e.prototype.onDisable = function () {
    h.Util.hideSingleCustomAd(), h.Util.event_dispatcher.remove(this), this.iscb = !1, l["default"].isMatchView = !1;
  }, e.prototype.start = function () {
    this.portraitNode.active = !1, this.powerValue.node.addComponent(p["default"]).init(2, h.Util.getCurItemPower(l["default"].getCurCarPower()), "", !0), this.refreshBoxStatus(), h.Util.videoExposure(u.VideoTab.dim19);
  }, e.prototype.onSetVitTime = function () {
    var t = this;

    if (!(l["default"].vitData.num >= y.Vit_Init_Num)) {
      var e = function e() {
        l["default"].vitData.num >= y.Vit_Init_Num && clearInterval(t.nIntervalHandle);
        var e = l["default"].vitData.time + 12e4,
            o = new Date().getTime(),
            i = Math.floor((e - o) / 1e3);
        Math.floor(i / 60), i <= 0 && l["default"].saveVitData(!0, 1);
      },
          o = y.Vit_Init_Num - l["default"].vitData.num,
          i = new Date().getTime() - l["default"].vitData.time,
          n = Math.floor(i / 12e4);

      n >= o ? l["default"].saveVitData(!0, o) : (l["default"].saveVitData(!0, n), this.nIntervalHandle = setInterval(e, 1e3), e());
    }
  }, e.prototype.refreshBoxStatus = function () {
    for (var t = 0; t < this.blocks.length; t++) {
      this.blocks[t].active = !1;
    }

    var e = l["default"].nArenaWinTotal % 3;

    for (t = 0; t < e; t++) {
      this.blocks[t].active = !0;
    }

    l["default"].nArenaWinTotal >= 3 ? this.redPointNode.active = !0 : this.redPointNode.active = !1;
    var o = Math.floor(l["default"].nArenaWinTotal / 3);
    this.boxValue.string = o.toString();
  }, e.prototype.onBtnGetBoxGift = function () {
    if (this.redPointNode.active) {
      var t = cc.instantiate(this.pfb_box);
      cc.find("Canvas").addChild(t), l["default"].isArenaView = !0, console.log("点击竞技宝箱"), this._gameControl && this._gameControl.playSound(this.openBox), t.getComponent(d["default"]).showOpenBoxView(d.Box_Type.senior, null), l["default"].saveArenaWinTotal(!1), this.refreshBoxStatus();
    }
  }, e.prototype.close = function () {
    var t = this;
    v.SceneManager.Instance.runScene(v.SceneName.hall, function () {
      h.Util.is_VIVO() && !l["default"].bAuditMode && (h.Util.hideNativeGridAd(), h.Util.hideHallBanner(), t.scheduleOnce(function () {
        h.Util.showNativeGridAd();
      }, 100));
    });
  }, e.prototype.initView = function (t) {
    this._gameControl = t, this.initRightInfo();
  }, e.prototype.refreshTime = function () {
    var t = this.getTime();
    t < 0 && (l["default"].nArenaWinTotal % 3 == 1 ? this.starNumList = [1, 3, 3, 3, 3] : l["default"].nArenaWinTotal % 3 == 2 && (this.starNumList = [3, 3, 3, 3, 3]), this.refresh()), this.timeLabel.string = m["default"].parse_timestamp_time_hours(t);
  }, e.prototype.initRightInfo = function () {
    if (l["default"].arenaModeDataList.length > 0) for (var t = 0; t < l["default"].arenaModeDataList.length; t++) {
      var e = l["default"].arenaModeDataList[t],
          o = cc.instantiate(this.rolePrefab);
      this._roles.push(o), o.getComponent(_["default"]).initViewData(this._gameControl, this, this._gameLogic, e, this.node, !1), o.getComponent(_["default"]).addEventListener();
    }
    this.frame_buttom.interactable = !0, this.btnRefreshOnce.interactable = !0, this.schedule(this.refreshTime.bind(this), .5);
  }, e.prototype.loadRightInfo = function () {
    return r(this, void 0, void 0, function () {
      var t = this;
      return s(this, function (e) {
        switch (e.label) {
          case 0:
            return [4, this.initNameInfo()];

          case 1:
            return e.sent(), [4, this.initHeadUrlInfo()];

          case 2:
            return e.sent(), [4, this.loadHeadSprite(this.headUrlList)];

          case 3:
            return e.sent(), this.portraitNode.active = !0, this.scheduleOnce(function () {
              t.showRightInfo(), t.getRoleInfo();
            }, .5), [2];
        }
      });
    });
  }, e.prototype.onBtnRefresh = function () {
    var t = this;
    l["default"].videoTab = u.VideoTab.dim19, h.Util.showRewardVideo(function () {
      t.starNumList = [1, 1, 2, 3, 3], t.refresh();
    }, null, null, !1);
  }, e.prototype.onBtnRefreshOnce = function () {
    return r(this, void 0, void 0, function () {
      var t, e, o, i, n, a, r, c, d, p, u, f, m, y;
      return s(this, function (s) {
        switch (s.label) {
          case 0:
            return console.log(l["default"].userArenaData), l["default"].userArenaData.canRefresh ? (l["default"].userArenaData.canRefresh = !1, this.refreshArr(), [4, this.initNameInfo()]) : (g["default"].show("击败一名对手获得换人机会"), [2]);

          case 1:
            return s.sent(), [4, this.initHeadUrlInfo()];

          case 2:
            return s.sent(), [4, this.loadHeadSprite(this.headUrlList)];

          case 3:
            for (s.sent(), t = 0, e = l["default"].arenaModeDataList; t < e.length; t++) {
              p = e[t], this._headUrlArr.push(p.headUrl);
            }

            for (o = 0, i = l["default"].arenaModeDataList; o < i.length; o++) {
              p = i[o], this._nameArr.push(p.name);
            }

            if (n = h.Util.getRandomInt(0, this._roles.length), a = this.starNumList[n], l["default"].userArenaData.date != new Date().getDate()) {
              for (r = [], c = 0, d = l["default"].arenaModeDataList; c < d.length; c++) {
                (p = d[c]).star > 2 && r.push(l["default"].arenaModeDataList.indexOf(p));
              }

              r.length > 0 && (n = r[Math.floor(Math.random() * r.length)], a = 1);
            }

            return l["default"].userArenaData.date = new Date().getDate(), l["default"].saveRefreshArenaData(), u = l["default"].arenaModeDataList[n], this.headUrl = this.selectInfo(this._headUrlArr, this.headUrlList), this.nameLabel.string = this.selectInfo(this._nameArr, this.rNameList), f = cc.v3(u.pos.x, u.pos.y), m = {
              name: this.nameLabel.string,
              headUrl: this.headUrl,
              power: 0,
              star: a,
              grade: 1,
              pos: {
                x: f.x,
                y: f.y
              }
            }, y = cc.instantiate(this.rolePrefab), this._roles[n].destroy(), this._roles[n] = y, y.getComponent(_["default"]).initViewData(this._gameControl, this, this._gameLogic, m, this.node, !1, !0, n), y.getComponent(_["default"]).addEventListener(), [2];
        }
      });
    });
  }, e.prototype.refreshArr = function () {
    this._nameArr = [], this._headUrlArr = [], this.headUrlList = [], this.rNameList = [], this.rHeadSpriteList = [];
  }, e.prototype.refresh = function () {
    this.refreshArr(), this.refreshStorageTime(), this.frame_buttom.interactable = !1, this.btnRefreshOnce.interactable = !1, this.node.getChildByName("btn_back").getComponent(cc.Button).interactable = !1;

    for (var t = 0; t < this._roles.length; t++) {
      var e = this._roles[t];
      e && e.destroy();
    }

    this._roles = [], l["default"].arenaModeDataList = [], this.loadRightInfo();
  }, e.prototype.selected = function (t) {
    this.frame_buttom.node.active = !1, this.btnRefreshOnce.node.active = !1;

    for (var e = 0; e < this._roles.length; e++) {
      this._roles[e] != t && this._roles[e].destroy();
    }
  }, e.prototype.getTime = function () {
    return f.BaseStorage.getInt(u.BaseStorageKey.ArenaRefresh, 0) - new Date().getTime();
  }, e.prototype.refreshStorageTime = function () {
    var t = new Date().getTime() + m["default"].convert_hours_to_milliseconds(1);
    f.BaseStorage.setInt(u.BaseStorageKey.ArenaRefresh, t);
  }, e.prototype.showRightInfo = function () {
    this.schedule(this.loopDisplay, .1);
  }, e.prototype.getRoleInfo = function () {
    this._index = 0, this.schedule(this.loopRoleData, 1);
  }, e.prototype.addRoleEvent = function () {
    for (var t = 0; t < this._roles.length; t++) {
      this._roles[t].getComponent(_["default"]).addEventListener();
    }
  }, e.prototype.selectInfo = function (t, e) {
    for (var o;;) {
      o = e[h.Util.getRandomInt(0, e.length - 1)];

      for (var i = !0, n = 0; n < t.length; n++) {
        if (o == t[n]) {
          i = !1;
          break;
        }
      }

      if (i) {
        t.push(o);
        break;
      }
    }

    return o;
  }, e.prototype.initNameInfo = function () {
    var t = this;
    return new Promise(function (e) {
      cc.loader.loadRes("database/user_name", cc.JsonAsset, function (o, i) {
        if (o) ;else for (var n = i.json, a = h.Util.GetRandomNumberArray(0, n.length, 30, 1), r = 0; r < a.length; r++) {
          t.rNameList.push(n[a[r]]);
        }
        e("success");
      });
    });
  }, e.prototype.initHeadUrlInfo = function () {
    var t = this;
    return new Promise(function (e) {
      cc.loader.loadRes("database/user_head", cc.JsonAsset, function (o, i) {
        if (o) cc.log(o);else for (var n = i.json, a = h.Util.GetRandomNumberArray(0, n.length, 30, 1), r = 0; r < a.length; r++) {
          t.headUrlList.push(n[a[r]]);
        }
        e("success");
      });
    });
  }, e.prototype.loadHeadSprite = function (t) {
    var e = this;
    return new Promise(function (o) {
      cc.assetManager.loadBundle("Role", function (i, n) {
        if (i) return cc.error(i);
        cc.log("load resources subpackage (Role) successfully.");

        for (var a = 0; a < t.length; a++) {
          n.load(t[a], cc.SpriteFrame, function (t, o) {
            e.rHeadSpriteList.push(o);
          });
        }

        o("success");
      });
    });
  }, a([w(cc.AudioClip)], e.prototype, "openBox", void 0), a([w(cc.Node)], e.prototype, "portraitNode", void 0), a([w(cc.Node)], e.prototype, "titleNode", void 0), a([w(cc.Node)], e.prototype, "tagNode", void 0), a([w(cc.Label)], e.prototype, "powerValue", void 0), a([w(cc.Node)], e.prototype, "boxNode", void 0), a([w(cc.Node)], e.prototype, "redPointNode", void 0), a([w(cc.Label)], e.prototype, "boxValue", void 0), a([w(cc.Sprite)], e.prototype, "portraitIcon", void 0), a([w(cc.Label)], e.prototype, "nameLabel", void 0), a([w(cc.Label)], e.prototype, "timeLabel", void 0), a([w(cc.Prefab)], e.prototype, "rolePrefab", void 0), a([w(cc.Prefab)], e.prototype, "pfb_box", void 0), a([w(cc.Button)], e.prototype, "frame_buttom", void 0), a([w([cc.Node])], e.prototype, "blocks", void 0), a([w(cc.Node)], e.prototype, "videoIcon", void 0), a([w(cc.Node)], e.prototype, "TTVideoIcon", void 0), a([w(cc.Node)], e.prototype, "btnVideo", void 0), a([w(cc.Button)], e.prototype, "btnRefreshOnce", void 0), a([b], e);
}(cc.Component);

o["default"] = S;

cc._RF.pop();